<template>
    <div class="e-form">
        <div class="title">{{ formData.projectName }}公开招标</div>
        <div class="tabs">
            <el-tabs
                tab-position="left"
                v-model="tabsName"
                @tab-click="onChangeTab"
            >
                <el-tab-pane
                    label="基本信息"
                    name="baseInfo"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="招标包件信息"
                    name="package"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="企业主要业绩"
                    name="enterprise"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="资质信息"
                    name="quaInfo"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <div>
                    <div id="baseInfoCon" class="con">
                        <div class="tabs-title" id="baseInfo">基本信息</div>
                        <div style="width: 100%" class="form">
                            <el-form
                                :model="formData"
                                label-width="170px"
                                :rules="rules"
                                ref="ruleForm"
                            >
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item
                                            label="统一社会信用代码"
                                            prop="unitCode"
                                        >
                                            <el-input
                                                v-model="formData.unitCode"
                                                placeholder="请先输入统一社会信用代码"
                                                @blur="
                                                    unitCodeBlur(
                                                        formData.unitCode
                                                    )
                                                "
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item
                                            label="投标单位"
                                            prop="unitName"
                                        >
                                            <el-input
                                                v-model="formData.unitName"
                                                :disabled="unitCodeState"
                                                :maxlength="50"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item
                                            label="法人代表"
                                            prop="legalRepresentative"
                                        >
                                            <el-input
                                                v-model="
                                                    formData.legalRepresentative
                                                "
                                                :disabled="unitCodeState"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item
                                            label="注册资本（万元）"
                                            prop="registerCaptial"
                                        >
                                            <el-input
                                                v-model.number="
                                                    formData.registerCaptial
                                                "
                                                v-enterFloat2
                                                :disabled="unitCodeState"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item
                                            label="联系电话（手机）"
                                            prop="telephone"
                                        >
                                            <el-input
                                                v-model="formData.telephone"
                                                :disabled="
                                                    unitCodeState &&
                                                    unitCodeState2
                                                "
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="邮箱" prop="email">
                                            <el-input
                                                v-model="formData.email"
                                                :disabled="unitCodeState"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="传真">
                                            <el-input
                                                v-model="formData.fax"
                                                :disabled="unitCodeState"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item
                                            label="邮编"
                                            prop="zipCode"
                                        >
                                            <el-input
                                                placeholder="请填写"
                                                :disabled="unitCodeState"
                                                v-model="formData.zipCode"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row style="align-items: stretch">
                                    <el-col :span="12">
                                        <el-form-item
                                            label="纳税类别："
                                            prop="taxpayerType"
                                        >
                                            <el-radio-group
                                                @change="radioChange($event)"
                                                :disabled="unitCodeState"
                                                v-model="formData.taxpayerType"
                                            >
                                                <el-radio
                                                    v-for="item in payTaxesTypeList"
                                                    :key="item.kvId"
                                                    :label="item.kvKey"
                                                    :disabled="item.disabled"
                                                    :value="item.kvValue"
                                                ></el-radio>
                                            </el-radio-group>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="是否为境外单位">
                                            <el-switch
                                                :width="60"
                                                v-model="formData.isAbroad"
                                                :disabled="unitCodeState"
                                                class="main-el-switch"
                                                active-color="#13ce66"
                                                inactive-color="#D2D2D2"
                                                active-value="1"
                                                inactive-value="0"
                                                active-text="是"
                                                inactive-text="否"
                                            >
                                            </el-switch>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item
                                            label="供应商类型"
                                            prop="outsourceTypeKey"
                                        >
                                            <el-checkbox
                                                style="margin: 0px 30px 5px 0px"
                                                :indeterminate="isIndeterminate"
                                                v-model="checkAll"
                                                @change="handleCheckAllChange"
                                                :disabled="unitCodeState"
                                            >
                                                全选
                                            </el-checkbox>
                                            <el-checkbox-group
                                                v-model="
                                                    formData.outsourceTypeKey
                                                "
                                                @change="
                                                    handleCheckedCitiesChange
                                                "
                                            >
                                                <el-checkbox
                                                    :disabled="unitCodeState"
                                                    v-for="item in typeList"
                                                    :key="item.kvId"
                                                    :label="item.kvKey"
                                                    :value="item.kvId"
                                                ></el-checkbox>
                                            </el-checkbox-group>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item
                                            label="注册地址"
                                            prop="registerAddress"
                                        >
                                            <SelectAddr
                                                v-model="
                                                    formData.registerAddress
                                                "
                                                :disabled="unitCodeState"
                                                @getLabel="getAddrLabel"
                                                lazy
                                                showCountry
                                                style="width: 100%"
                                            ></SelectAddr>
                                            <!-- 详细地址 -->
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                        </div>
                    </div>

                    <div id="packageCon" class="con e-table">
                        <div class="tabs-title" id="package">
                            <!-- <span style="color: red">*</span> -->
                            招标包件信息
                        </div>
                        <el-table
                            :data="formData.enrollPackage"
                            border
                            style="width: 100%"
                            :cell-class-name="cellClsNm"
                            @cell-click="cellClick"
                            @cell-mouse-enter="cellMouseEnter"
                            @cell-mouse-leave="cellMouseLeave"
                            @selection-change="
                                selectionChange('packageTableData', $event)
                            "
                            :max-height="$store.state.tableHeight"
            ref="table"
            v-sortTable="{ tableData: tableData, _this: this, ref: 'table' }"
                        >
                            <el-table-column   type="selection" width="55">
                            </el-table-column>
                            <el-table-column
                                width="200"
                                prop="itemNo"
                                label="包件号"
                            >
                            </el-table-column>
                            <el-table-column
                                width="200"
                                prop="name"
                                label="包件名称"
                            >
                            </el-table-column>
                            <el-table-column
                                min-width="150"
                                prop="priceLimit"
                                label="招标最高限价（元）"
                            >
                            </el-table-column>
                        </el-table>
                    </div>

                    <div id="enterpriseCon" class="con e-table">
                        <div class="tabs-title" id="enterprise">
                            <!-- <span style="color: red">*</span> -->
                            企业主要业绩
                        </div>

                        <div>
                            <el-button
                                class="btn-greenYellow"
                                @click="enterpriseAdd"
                                v-if="!unitCodeState"
                                >新增</el-button
                            >
                            <el-button
                                class="btn-delete"
                                  @click="delete1"
                                v-if="!unitCodeState"
                                >删除</el-button
                            >
                               <div
                            style="margin-bottom: 20px"
                            class="errorMsg"
                            v-if="errorMsg1.length > 0"
                        >
                            <span
                                style="display: block"
                                v-for="(item, index) in errorMsg1"
                                :key="index"
                            >
                                {{ item }}
                            </span>
                        </div>
                        </div>
                        <el-table
                            :data="formData.enterpriseAchievement"
                            border
                            style="width: 100%; margin-top: 20px"
                            :cell-class-name="cellClsNm"
                            @select="selectClick1"
                            @cell-click="cellClick"
                            @cell-mouse-enter="cellMouseEnter"
                            @cell-mouse-leave="cellMouseLeave"
                            @selection-change="
                                selectionChange('enterpriseTableData', $event)
                            "
                            :max-height="$store.state.tableHeight"
            ref="table"
            v-sortTable="{ tableData: tableData, _this: this, ref: 'table' }"
                        >
                            <el-table-column
                                width="100"
                                v-if="!unitCodeState"
                                label="操作"
                                type="selection"
                            >
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="contractName"
                                label="合同名称"
                                label-class-name=""
                            >
                                <template slot-scope="{ row }">
                                    <el-input
                                        v-model="row.contractName"
                                        placeholder="请输入内容"
                                        :maxlength="50"
                                        :disabled="unitCodeState"
                                    ></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="projectName"
                                label="项目名称"
                                label-class-name=""
                            >
                                <template slot-scope="{ row }">
                                    <el-input
                                        v-model="row.projectName"
                                        placeholder="请输入内容"
                                        :maxlength="50"
                                        :disabled="unitCodeState"
                                    ></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="contractAmount"
                                label="合同金额（元）"
                                label-class-name=""
                            >
                                <template slot-scope="{ row }">
                                    <el-input
                                        v-model="row.contractAmount"
                                        placeholder="请输入内容"
                                        v-enterJustFloat
                                        :disabled="unitCodeState"
                                    ></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="workContent"
                                label="所承担工作内容"
                                label-class-name=""
                            >
                                <template slot-scope="{ row }">
                                    <el-input
                                        v-model="row.workContent"
                                        placeholder="请输入内容"
                                        :disabled="unitCodeState"
                                    ></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="startTime"
                                label="开工时间"
                            >
                                <template slot-scope="{ row }">
                                    <el-date-picker
                                        :disabled="unitCodeState"
                                        v-model="row.startTime"
                                        type="date"
                                        placeholder="选择日期"
                                        value-format="yyyy-MM-dd"
                                        @blur="timeBlur(row)"
                                    >
                                    </el-date-picker>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="endTime"
                                label="竣工时间"
                            >
                                <template slot-scope="{ row }">
                                    <el-date-picker
                                        v-model="row.endTime"
                                        type="date"
                                        :disabled="unitCodeState"
                                        placeholder="选择日期"
                                        value-format="yyyy-MM-dd"
                                        :picker-options="pickerOptions(row)"
                                    >
                                    </el-date-picker>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="personInChar"
                                label="项目负责人"
                            >
                                <template slot-scope="{ row }">
                                    <el-input
                                        v-model="row.personInChar"
                                        placeholder="请输入内容"
                                        :maxlength="50"
                                        :disabled="unitCodeState"
                                    ></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="witness"
                                label="业绩证明人"
                                label-class-name=""
                            >
                                <template slot-scope="{ row }">
                                    <el-input
                                        v-model="row.witness"
                                        placeholder="请输入内容"
                                        :maxlength="50"
                                        :disabled="unitCodeState"
                                    ></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="witnessPhone"
                                label="证明人电话"
                                label-class-name=""
                            >
                                <template slot-scope="{ row }">
                                    <el-input
                                        v-model="row.witnessPhone"
                                        :disabled="unitCodeState"
                                        placeholder="请输入内容"
                                    ></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="250"
                                prop="proveFile"
                                label="证明附件"
                            >
                                <template slot-scope="{ row }">
                                    <div class="affix">
                                         <el-upload
                                    style="margin: 7px 5px 0px 0px"
                                    class="upload-demo"
                                    :action="uploadUrl"
                                    :data="{
                                        bucketName,
                                        relationId,
                                        orgCode
                                    }"
                                    :before-upload="beforeAvatarUpload"
                                    :accept="accept"
                                    :on-success="attachOnSuccess1"
                                    :http-request="uploadBefore1"
                                    :show-file-list="false"
                                    name="files"
                                        >
                                    <el-button
                                    size="mini"
                                    type="primary"
                                    >上传</el-button
                                            >
                                        </el-upload>
                                        <div class="right">
                                            <div class="fileName">
                                                <a
                                                    :href="row.filePath"
                                                    target="_blank"
                                                    v-if="row.filePath"
                                                    >{{ row.fileName }}</a
                                                >
                                            </div>
                                            <!-- 正好没返path，没附件id反正也删不掉 -->
                                            <i
                                                slot="reference"
                                                class="el-icon-delete"
                                                style="
                                                    cursor: pointer;
                                                    font-size: 20px;
                                                "
                                                v-if="row.filePath"
                                                @click="delFile(row)"
                                            ></i>
                                        </div>
                                    </div>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>

                    <div id="quaInfoCon" class="con e-table">
                        <div class="tabs-title" id="quaInfo">
                            <!-- <span style="color: red">*</span> -->
                            资质信息
                        </div>
                        <div>
                            <el-button
                                class="btn-greenYellow"
                                @click="quaInfoAdd"
                                v-if="!unitCodeState"
                                >新增</el-button
                            >
                            <el-button
                                class="btn-delete"
                                  @click="delete2"
                                v-if="!unitCodeState"
                                >删除</el-button
                            >
                           <div
                            style="margin-bottom: 20px"
                            class="errorMsg"
                            v-if="errorMsg.length > 0"
                        >
                            <span
                                style="display: block"
                                v-for="(item, index) in errorMsg"
                                :key="index"
                            >
                                {{ item }}
                            </span>
                        </div>
                        </div>
                        <el-table
                            :data="formData.enrollCertificates"
                            border
                            style="width: 100%; margin-top: 20px"
                            :cell-class-name="cellClsNm"
                            @select="selectClick2"
                            @cell-click="cellClick"
                            @cell-mouse-enter="cellMouseEnter"
                            @cell-mouse-leave="cellMouseLeave"
                            @selection-change="
                                selectionChange('quaInfoTableData', $event)
                            "
                            :max-height="$store.state.tableHeight"
            ref="table"
            v-sortTable="{ tableData: tableData, _this: this, ref: 'table' }"
                        >
                            <el-table-column
                                width="100"
                                label="操作"
                                type="selection"
                                 v-if="!unitCodeState"
                            >
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="certificateType"
                                label="证书类型"
                            >
                                <template slot-scope="{ row }">
                                    <div >
                                        <el-select
                                            v-model="row.certificateType"
                                            placeholder="请选择"
                                            :disabled="unitCodeState"
                                            @change="
                                                certificateTypeChange(
                                                    $event,
                                                    row
                                                )
                                            "
                                        >
                                            <el-option
                                                v-for="item in certType"
                                                :key="item.kvId"
                                                :label="item.kvKey"
                                                :value="item.kvKey"
                                            >
                                            </el-option>
                                        </el-select>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="certificateNo"
                                label="证书编号"
                            >
                                <template slot-scope="{ row }">
                                    <div>
                                        <el-input
                                            v-model="row.certificateNo"
                                            placeholder="请输入内容"
                                            :disabled="
                                                row.certificateType ===
                                                '营业执照'||unitCodeState
                                            "
                                        ></el-input>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="certificateGrade"
                                label="主营范围/资质等级"
                            >
                                <template slot-scope="{ row }">
                                    <div >
                                        <span>
                                            <el-input
                                                v-if="
                                                    row.certificateType ===
                                                        '营业执照' ||
                                                    row.certificateType ===
                                                        '资质证书'
                                                "
                                                readonly
                                                v-model="row.certificateGrade"
                                                placeholder="请选择"
                                            >
                                                <i
                                                    v-if="!unitCodeState"
                                                    slot="suffix"
                                                    class="el-icon-document-copy"
                                                    @click="onSelect(row)"
                                                    style="cursor: pointer"
                                                ></i>
                                            </el-input>
                                        </span>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="startTime"
                                label="有效开始日期"
                            >
                                <template slot-scope="{ row }">
                                    <el-date-picker
                                        v-model="row.startTime"
                                        type="date"
                                        :disabled="unitCodeState"
                                        placeholder="选择日期"
                                        value-format="yyyy-MM-dd"
                                        @blur="timeBlur(row)"
                                    >
                                    </el-date-picker>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="250"
                                prop="endTime"
                                label="有效结束日期"
                            >
                                <template slot-scope="{ row }">
                                    <span>
                                        <el-date-picker
                                            v-model="row.endTime"
                                            type="date"
                                            placeholder="选择日期"
                                            :disabled="unitCodeState"
                                            value-format="yyyy-MM-dd"
                                            :picker-options="pickerOptions(row)"
                                            style="width: 150px"
                                        >
                                        </el-date-picker>
                                        <el-button
                                            class="btn-blue"
                                            style="margin-left: 10px"
                                            size="mini"
                                            @click="forever(row, 'endTime')"
                                            >永久</el-button
                                        >
                                    </span>
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="fileName"
                                label="文件名"
                            >
                            </el-table-column>
                            <el-table-column
                                width="150"
                                prop="fileSize"
                                label="大小"
                            >
                                <template
                                    slot-scope="{ row }"
                                    v-if="row.fileSize"
                                >
                                    {{ bytesToSize(row.fileSize) }}
                                </template>
                            </el-table-column>
                            <el-table-column
                                width="200"
                                prop="upTime"
                                label="上传时间"
                            >
                            </el-table-column>
                            <el-table-column width="250" label="附件">
                                <template slot-scope="{ row }">
                                    <div class="affix">
                                        <el-upload
                                    style="margin: 7px 5px 0px 0px"
                                    class="upload-demo"
                                    :action="uploadUrl"
                                    :data="{
                                        bucketName,
                                        relationId,
                                        orgCode
                                    }"
                                    :before-upload="beforeAvatarUpload"
                                    :accept="accept"
                                    :on-success="attachOnSuccess"
                                    :http-request="uploadBefore"
                                    :show-file-list="false"
                                    name="files"
                                     >
                                    <el-button
                                    size="mini"
                                    type="primary"
                                    v-if="!unitCodeState"
                                    >上传</el-button
                                            >
                                </el-upload>
                                        <div class="right">
                                            <div class="fileName">
                                                <a
                                                    :href="row.filePath"
                                                    target="_blank"
                                                    >{{ row.fileName }}</a
                                                >
                                            </div>
                                            <i
                                                slot="reference"
                                                class="el-icon-delete"
                                                style="
                                                    cursor: pointer;
                                                    font-size: 20px;
                                                "
                                                v-if="
                                                    row.fileName &&
                                                    !unitCodeState
                                                "
                                                @click="delFile(row)"
                                            ></i>
                                        </div>
                                    </div>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </div>
                <div style="font-weight: bold">
                    承诺：我代表公司承诺，上述信息正确、合法有效、若招标人（发起人）在招标过程中或中标后发现上述信息存在虚假、我们承诺承袒由此造成的所有责任（包括但不限于无条件故弃中标）。
                </div>
            </el-tabs>
        </div>

        <div class="buttons">
            <el-button type="primary" class="btn-blue" @click="submit"
                >提交</el-button
            >
            <el-button @click="reset">重置</el-button>
        </div>
        <div id="seat" :style="{ height: seatHeight + 'px' }"></div>
        <el-dialog
            :title="dialogTitle"
            :visible.sync="dialogVisible"
            width="50%"
            style="padding: 50px"
        >
            <span>
                <el-tree
                    :props="props"
                    :load="loadNode"
                    lazy
                    show-checkbox
                    style="margin-top: 20px"
                    @check-change="treeCheckChange"
                    :key="treeKey"
                >
                </el-tree>
            </span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="diaLogSubmit"
                    >确 定</el-button
                >
            </span>
        </el-dialog>
    </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
// import ComTreeTable from '@/templates/table/treeTable.vue'
// import ComTreeFile from '@/templates/table/treeFile.vue'
// import ComPagination from '@/components/pagination/pagination.vue'
import enrollRequest from '@/api/tender/enroll.js'
import materialZhouCaiLeasingRequest from '@/api/tender/materialZhouCaiLeasing.js'
import tenderRequest from '@/api/tender/tender.js'
import { getOrgById, getOrgByParentId } from '@/api/base/system'
import commonRequest from '@/api/tender/common.js'
import call from '@/api/OutsourcingartyAdmin/getAllType.js'
import ossRequest from '@/api/oss/oss.js'
import { mapState } from 'vuex'
import SelectAddr from '@/components/common/addrComp'
import { bytesToSize, getUuid } from '@/utils/common'
// import { random19Num } from '@/utils/common'
import { uidBuilder } from '@/api/base/uid.js'
import openBiddingRequest from '@/api/tender/openBidding.js'
import {
    creditCodeVerification,
    isEmail,
    isName,
    isPhone,
    isPostCode,
    isFax
} from '@/utils/rules'
export default {
    data () {
        return {
            unitCodeState: true, // 信用代码是否通过状态，true全禁止，false可编辑
            unitCodeState2: true, // 信用代码通过，代理人、固定电话、联系电话、企业主要业绩可以编辑
            // 基础信息
            formData: {
                abandondeExplain: '',
                abandonedReason: '',
                abandonedTime: '',
                abandonedUser: '',
                abandonedUserId: '',
                applyUnit: '',
                applyUnitId: '',
                billId: '',
                email: '',
                creditLevel: '',
                enrollCertificates: [], //资质信息
                enrollPackage: [], //包件
                enrollTime: '',
                enterpriseAchievement: [], //企业主要业绩
                fax: '',
                fixedTelephone: '',
                gmtCreate: '',
                gmtModified: '',
                isAbroad: 0,
                isOutsideSubcontractors: null,
                legalRepresentative: '',
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: '',
                nullifyDescription: '',
                nullifyReason: '',
                orgId: '',
                orgName: '',
                outsourceType: [], //供应商id
                outsourceTypeKey: [], //供应商类型
                packageIds: '',
                packageName: '',
                projectName: '',
                proxyUser: '',
                qualificationLevelName: '',
                registerAddress: '',
                registerCaptial: 0,
                state: 0,
                taxpayerType: '',
                telephone: '',
                tenderApplyId: '',
                tenderApplyNo: '',
                tenderType: 0,
                unitCode: '',
                unitId: '',
                unitName: '',
                workId: '',
                zipCode: ''
            },
            // 包件列表
            packageTableData: [],
            certType: [], //证书类型
            rowIndex: '', //资质点击的行数
            rowIndex1: '', //企业业绩点击的行数
            errorMsg: [], //资质信息错误提示
            errorMsg1: [], //主要业绩信息错误提示
            userInfoData: {}, //登录信息保存
            deleteData1: [], //资质信息删除数据
            deleteData2: [], //主要管理人删除数据
            // 包件名字
            // packageName: '',
            // 资质信息
            quaInfoTableData: [],
            // 历史业绩
            enterpriseTableData: [],
            // upData: {
            //     relationId: ''
            // },
            bucketName: 'tender',
            uploadUrl: '/oss/uploader',
            accept: '.jpg,jpeg,.png,.pdf',
            relationId: '',
            selection: { packageTableData: [] },
            tenderData: {}, //基础招标信息
            managerTableData: [],
            attachTableData: [],
            // enterpriseFormData: [],
            tabsName: 'baseInfo',
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            tableData: [],
            value: '',
            // el-input: '',
            test: '',
            selectData: [],
            selectTableColumnAttr: [
                {
                    label: '单据编号',
                    prop: 'billNo'
                },
                {
                    label: '拟招标项目名称',
                    prop: 'tenderName'
                },
                {
                    label: '单据日期',
                    prop: 'gmtCreate'
                },
                {
                    label: '单据机构名称',
                    prop: 'orgName'
                }
            ],
            selectTableColumnWidth: {
                leftWidth: '150',
                rightWidth: '100'
            },
            selectDataPagination: {},
            fileList4: [],
            isIndeterminate: true,
            checkAll: false, //是否全选
            typeList: [],
            pickerOptions: row => {
                return {
                    disabledDate (time) {
                        return (
                            time.getTime() <
                            new Date(row.startTime).getTime() + 86400000
                        )
                    }
                }
            },
            // 验证
            rules: {
                // 统一社会信用代码
                unitCode: [
                    {
                        required: true,
                        validator: creditCodeVerification,
                        trigger: 'blur'
                    }
                ],
                //供应商名称
                supplierName: [
                    {
                        required: true,
                        message: '请输入供应商名称',
                        trigger: 'blur'
                    }
                ],
                //类型
                outsourceTypeKey: [
                    { required: true, message: '请选择类型', trigger: 'change' }
                ],
                //法人代表
                legalRepresentative: [
                    {
                        required: true,
                        validator: isName,
                        trigger: 'blur'
                    }
                ],
                //电话
                telephone: [
                    {
                        required: true,
                        validator: isPhone,
                        trigger: 'blur'
                    }
                ],
                //邮箱
                email: [{ validator: isEmail, trigger: 'blur' }],
                //邮编
                postCode: [
                    {
                        validator: isPostCode,
                        trigger: 'blur'
                    }
                ],
                //传真
                fax: [
                    {
                        validator: isFax,
                        trigger: 'blur'
                    }
                ],
                //纳税类别
                taxpayerType: [
                    {
                        required: true,
                        message: '请选择纳税类别',
                        trigger: 'change'
                    }
                ],
                //投标单位
                unitName: [
                    {
                        required: true,
                        message: '请输入投标单位',
                        trigger: 'change'
                    }
                ],
                // 注册地址
                registerAddInfo: [
                    {
                        required: true,
                        message: '请选择注册地址',
                        trigger: 'change'
                    }
                ],
                //注册资本
                registerCaptial: [
                    {
                        required: true,
                        message: '请输入注册资本',
                        trigger: 'blur'
                    }
                ]
            },
            payTaxesTypeList: [], //纳税类别
            messageError: {
                enterpriseTableData: '' // 企业业绩信息
            },
            dialogVisible: false,
            dialogTitle: '',
            props: {
                label: 'kvValue',
                // children: 'zones',
                isLeaf: 'isLeaf'
            },
            treeCheckSet: new Set(),
            row: null, //资质信息 主营范围/资质等级 回调弹窗保存的当前row
            treeKey: 0
        }
    },
    watch: {
        'formData.outsourceValue' (val) {
            console.log()
            val[val.findIndex(item => item === '施工合作')] = '施工分包'
        }
    },
    computed: {
        // 判断状态
        ...mapState(['userInfo']),
        statusLable () {
            return param => {
                const state = this.$store.state.equip.equipData.state
                const obj = state.find(x => x.value == param)
                if (obj !== undefined) {
                    return obj.label
                }
            }
        },
        tenderId () {
            // return this.formData.tenderApplyId
            return this.$route.query.tenderId || this.$route.query.billid //假数据
        },
        billId () {
            return this.$route.query.billId || this.$route.query.billid
        },
        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 72 - this.lastConHeight
        },
        orgCode () {
            return this.$store.state.userInfo.orgInfo.shortCode
        }
    },
    components: {
        SelectAddr
    },
    async created () {
        console.log('执行了11')
        this.formData.tenderApplyId = this.$route.query.tenderId
        this.userInfoData = JSON.parse(localStorage.getItem('vuex'))
        this.formData.orgId =  this.userInfoData.userInfo.orgInfo.orgId //初始化机构id
        this.formData.orgName =  this.userInfoData.userInfo.orgInfo.orgName //初始化机构名字
        this.formData.founderName = localStorage.getItem('userName')
        this.getTypeData() //进入页面获取类型选择框数据
        this.getTreeData( this.userInfoData.userInfo) //获取用户所在机构
        await this.getTenderData() // 获取招标基础信息
        this.getPackage() // 获取包件信息
    },
    mounted () {
        // 保存所有tabName
        const arr = [
            'baseInfo',
            'package',
            'enterprise',
            'quaInfo',
            'manager',
            'attach'
        ]
        // 获取最后一个内容区域的高度，计算底部空白
        this.getLastConHeight(arr)
        let $idsTop = []
        window.addEventListener('scroll', () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            if (this.clickTabFlag) {
                return
            }
            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    const itemTop = document.getElementById(item)?.offsetTop
                    return itemTop
                })
            }
            const scrollTop =
                document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                let item = $idsTop[i]
                if (scrollTop + 1 >= item) {
                    curLocal = i
                    break
                }
            }
            // 设置对应tabName
            this.tabsName = arr[curLocal]
        })

        this.screenWidth = document.documentElement.clientWidth - this.topHeight
        this.screenHeight = document.documentElement.clientHeight - this.topHeight
        window.addEventListener('resize', () => {
            this.screenWidth = document.documentElement.clientWidth - this.topHeight
            this.screenHeight = document.documentElement.clientHeight - this.topHeight
            $idsTop = arr.map(item => {
                const itemTop = document.getElementById(item)?.offsetTop
                return itemTop
            })
        })
    },
    beforeDestroy () {
        this.$notify.closeAll()
    },
    methods: {
        // 获取用户所在机构data
        async getTreeData (data = {}) {
            try {
                const orgInfo = await getOrgById({
                    orgId: data.orgInfo.orgId
                })
                // 如果类型是集团和分子公司，则管理机构为当前机构
                if (orgInfo.orgType == 1 || orgInfo.orgType == 2) {
                    this.formData.manageOrgName = this.formData.orgName
                    this.formData.manageOrgId = this.formData.orgId
                } else {
                    // 否则通过机构id来查询父级机构，管理机构为父级机构
                    const obj = await getOrgByParentId({
                        orgId: data.orgInfo.orgId
                    })
                    this.formData.manageOrgName = obj.parentName
                    this.formData.manageOrgId = obj.parentId
                }
            } catch (error) {
                alert(error.message)
            }
        },
        // 获取注册地址
        getAddrLabel (val) {
            this.formData.registerAdds = val
        },
        getTypeData () {
            call.getCredentialTree({ name: '外包方类型', id: '0' }).then(
                res => {
                    let id = ''
                    // 获取想要的类型id
                    res.map(item => {
                        if (item.kvKey == '供应商') {
                            id = item.kvId
                        }
                    })
                    call.getCredentialTree({
                        name: '外包方类型',
                        id: id
                    }).then(res => {
                        this.typeList = res
                    })
                }
            )
            call.getCredential('纳税类别').then(res => {
                this.payTaxesTypeList = res
            })
            //获取证书类型
            call.getCredential('供应商证书类型').then(res => {
                this.certType = res
            })
        },
        diaLogSubmit () {
            this.dialogVisible = false
            this.row.certificateGrade = [...this.treeCheckSet].join(',')
        },
        treeCheckChange (data, isCheck) {
            if (isCheck) {
                this.treeCheckSet.add(data.kvValue)
            } else {
                this.treeCheckSet.delete(data.kvValue)
            }
        },
        async loadNode (node, resolve) {
            if (node.level === 0) {
                const dicName = this.dialogTitle.includes('资质等级')
                    ? '资质等级'
                    : '外包方主营范围'
                const res = await commonRequest.getDicValueTree({
                    dicName,
                    isEnable: true,
                    parentId: 0
                })
                return resolve(res)
            }
            if (node.level >= 1) {
                const dicName = this.dialogTitle.includes('资质等级')
                    ? '资质等级'
                    : '外包方主营范围'
                const res = await commonRequest.getDicValueTree({
                    dicName,
                    isEnable: true,
                    parentId: node.data.kvId
                })
                return resolve(res)
            }
        },
        onSelect (row) {
            // 需要刷新 主营范围/证书等级 接口
            this.treeKey += 1
            // 弹窗后需要改变，所以保存
            this.row = row
            this.dialogVisible = true
            this.dialogTitle =
                row.certificateType === '营业执照'
                    ? '请选择主营范围'
                    : '请选择资质等级'
        },
        // 资质信息 证书类型切换
        certificateTypeChange (val, row) {
            // 证书类型，安全许可证，不能选择日期结束时间，根据有效期开始时间加3年
            // if (val === '安全生产许可证') {
            //     row.endTime = new Date(
            //         Date.parse(new Date(row.startTime)) + 31536000000 * 3 + 86400000
            //     )
            // }
            // 营业执照时，证书编号为信用代码
            if (val === '营业执照') {
                row.certificateNo = this.formData.unitCode
            }
        },
        changeIsAbroad (val) {
            // 是境外单位纳税类别可以选择小型
            if (val === 1 && this.formData.taxpayerType === '其他') {
                this.formData.taxpayerType = ''
            }
        },
        forever (row, name) {
            row[name] = '9999-12-30'
        },
        timeBlur (row) {
            if (
                new Date(row.startTime).getTime() >
                new Date(row.endTime).getTime()
            ) {
                row.endTime = null
            }
        },
        deleteTableRow (tableName) {
            if (this.selection[tableName].length === 0) return
            this.selection[tableName].forEach(item => {
                // 前端删除
                const deleteIndex = this[tableName].findIndex(
                    item2 => (item.recordId = item2.recordId)
                )
                this[tableName].splice(deleteIndex, 1)
            })
        },
        selectionChange (tabaleName, selection) {
            this.selection[tabaleName] = selection
        },
        // 资质信息增加
        quaInfoAdd () {
            this.formData.enrollCertificates.push({
                certificateGrade: '', //主营范围/资质等级
                certificateGradeId: '', //主营范围/资质等级
                certificateNo: '', //证书编号
                certificateType: '', //	证书类型
                endTime: '', //有效结束日期
                fileName: '', //文件名称
                filePath: '', //文件路径
                fileSize: '', //文件大小
                recordId: '', //记录ID
                startTime: '', //有效开始日期
                upUser: '', //上传人
                upUserId: '', //上传人ID
                uuid: getUuid(), //本地的uuid区分每条数据
            })
        },
        // 历史业绩增加
        enterpriseAdd () {
            this.formData.enterpriseAchievement.push({
                contractAmount: '', //合同金额
                contractName: '', //合同名称
                endTime: '', //竣工时间
                fileName: '', //证明附件名称
                filePath: '', //证明附件
                personInChar: '', //负责人
                projectName: '', //项目名称
                gmtCreate: '', //创建时间
                recordId: '', //记录ID
                startTime: '', //开工时间
                witness: '', //证明人
                witnessPhone: '', //证明人电话
                workContent: '', //	工作内容
                uuid: getUuid(), //本地的uuid区分每条数据
            })
        },
        // 提交
        async submit () {
            /**
             * 判断该数据是自己页面新增还是从库内查回来，如果newData为false则为库内单位
             * 如果是库内单位，则不验证必填，直接存到后端， 如果是库外单位则需要去验证必填
             */
            if (this.formData.isOutsideSubcontractors == '2') {
                if (
                    this.formData.enrollPackage &&
                    this.formData.enrollPackage.length != 0
                ) {
                    this.formData.enrollPackage.map(item=>{
                        item.unitCode = this.formData.unitCode //统一社会信用代码
                        item['packageId'] = item.billId //包件id
                        item['tenderApplyId'] = this.formData.tenderApplyId //招标id
                    })
                    if (this.formData.outsourceType instanceof Array) {
                        this.formData.outsourceType =
                            this.formData.outsourceType.join()
                    }
                    await tenderRequest
                        .weeklyMaterialLeasingCreate(this.formData)
                        .then(() => {
                            this.clientPop('suc', '提交成功')
                        })
                        .catch(() => {
                            this.clientPop('err', '提交失败')
                        })
                } else {
                    this.clientPop('suc', '请选择包件信息')
                }
            } else {
                // 验证错误信息
                this.errorMsg = [] //资质信息
                this.errorMsg1 = []//主要业绩
                let once = true //提示只执行一次
                // 验证通过
                let adopt = false //包建
                let adopt2 = false //资质信息是否通过
                let adopt3 = false//主要业绩
                this.$refs.ruleForm.validate(valid => {
                    if (!valid) {
                        this.onChangeTab({ name: 'baseInfo' })
                        return
                    } else {
                        // 包件信息
                        if (
                            this.formData.enrollPackage &&
                        this.formData.enrollPackage.length != 0
                        ) {
                            this.formData.enrollPackage.map(item=>{
                                item.unitCode = this.formData.unitCode //统一社会信用代码
                                item['packageId'] = item.billId //包件id
                                item['tenderApplyId'] = this.formData.tenderApplyId //招标id
                            })
                            adopt = true
                        } else {
                            adopt = false
                            this.clientPop('err', '请选择包件信息')
                        }
                        // 资质信息
                        if (this.formData.enrollCertificates.length > 0) {
                            // 首先将changeTy为-1的过滤掉
                            let data = this.formData.enrollCertificates.filter(item => {
                                return item.changeType != -1
                            })
                            this.errorMsg = [] //资质信息
                            let isContain = [] //定义证书类型临时数组
                            let newData = [] //定义不包含数据
                            // 将证书类型存入临时数组
                            isContain = data.map(item => {
                                return item.certificateType
                            })
                            // 判断哪些字段重复
                            var result = [] //不重复字段
                            var result2 = [] //重复字段
                            for (var i = 0; i < isContain.length; i++) {
                                if (result.indexOf(isContain[i]) == -1) {
                                    result.push(isContain[i])
                                } else {
                                    if (result2.indexOf(isContain[i]) == -1) {
                                        result2.push(isContain[i])
                                    }
                                }
                            }
                            // 判断你是否重复，如果重复不进行下一步判断
                            if (result2.length < 1) {
                                // 去重
                                let isContains = [...new Set(isContain)]
                                /**
                             * 12)勾选了境外单位或供应商类型只有其他的时候，则必须上传营业执照、法人证件，其他证书类型可传可不传
                             */
                                if (
                                    this.formData.outsourceTypeKey ==
                                    '6' ||
                                this.formData.isAbroad == 1
                                ) {
                                    let oldArry = ['营业执照', '法人证件'] // 营业执照、法人证件
                                    // 检验哪些不包含在该数组
                                    newData = oldArry.filter(item => {
                                        if (!isContains.includes(item)) {
                                            return item
                                        }
                                    })
                                } else {
                                    let oldArry = ['营业执照', '资质证书', '合格供方调查表', '企业资信信息', '法人证件'] // 营业执照、资质证书、合格供方调查表、企业资信信息、法人证件
                                    // 检验哪些不包含在该数组
                                    newData = oldArry.filter(item => {
                                        if (!isContains.includes(item)) {
                                            return item
                                        }
                                    })

                                }
                                if (newData.length < 1) {
                                    // 验证是否有数据
                                    let isStr = false
                                    this.formData.enrollCertificates.forEach((item, index) => {
                                        let str1 = `请完善第 ${index + 1} 行的`
                                        if (
                                            item.certificateType === '' ||
                                        item.certificateType === null
                                        ) {
                                            let str = '证书类型,'
                                            isStr = true
                                            str1 += str
                                        }
                                        if (
                                            item.startTime === '' ||
                                        item.startTime === null
                                        ) {
                                            let str = '开始时间,'
                                            isStr = true
                                            str1 += str
                                        }
                                        if (
                                            item.endTime === '' ||
                                        item.endTime === null
                                        ) {
                                            let str = '结束时间,'
                                            isStr = true
                                            str1 += str
                                        }
                                        if (
                                            (item.certificateType == '营业执照' ||
                                            item.certificateType == '资质证书') &&
                                        (item.certificateGrade === '' ||
                                            item.certificateGrade ===
                                                null)
                                        ) {
                                            let str = '供应商品/证书等级,'
                                            isStr = true
                                            str1 += str
                                        }
                                        if (
                                            item.fileName === '' ||
                                        item.fileName === null
                                        ) {
                                            let str = '资质附件,'
                                            isStr = true
                                            str1 += str
                                        }
                                        if (
                                            Date.parse(item.startTime) >=
                                        Date.parse(item.endTime)
                                        ) {
                                            let str = '结束时间必须大于开始时间'
                                            isStr = true
                                            str1 += str
                                        }
                                        if (
                                            item.certificateNo === '' ||
                                        item.certificateNo === null
                                        ) {
                                            isStr = true
                                            let str = '证书编号,'
                                            str1 += str
                                        }
                                        if (isStr) {
                                            this.errorMsg.push(str1)
                                        }
                                    })
                                    if (this.errorMsg.length > 0) {
                                        this.$emit('setError', 'aptitude')
                                        return
                                    } else {
                                        // 资质信息验证通过------------
                                        adopt2 = true
                                    }
                                } else {
                                    let newData1 = newData.join(',')
                                    this.errorMsg.push(`${newData1}` + '未填写')
                                }
                            } else {
                                if (result2.includes('')) {
                                    if(once) {
                                        this.errorMsg.push('请完善资质类型')
                                        once = false
                                    }
                                }else{
                                    result2.map(item => {
                                        this.certType.map(newItem => {
                                            if ( item == newItem.kvKey ) {
                                                this.errorMsg.push(
                                                `${newItem.kvKey}'重复'`
                                                )
                                            }
                                        })
                                    })
                                }
                            }
                        } else {
                            this.clientPop('err', '请选择资质信息')
                        }
                    }
                    //如果不是境外单位则必填一条数据
                    if (this.formData.isAbroad == '0') {
                        if (this.formData.enterpriseAchievement.length > 0) {
                            let isStr = false
                            this.formData.enterpriseAchievement.forEach((item, index) => {
                                let str1 = `请完善第 ${index + 1} 行的`
                                if (
                                    item.contractName === '' ||
                            item.contractName === null
                                ) {
                                    let str = '合同名称,'
                                    isStr = true
                                    str1 += str
                                }
                                if (
                                    item.projectName === '' ||
                            item.projectName === null
                                ) {
                                    let str = '项目名称,'
                                    isStr = true
                                    str1 += str
                                }

                                if (
                                    item.contractAmount === '' ||
                            item.contractAmount === null
                                ) {
                                    let str = '合同金额,'
                                    isStr = true
                                    str1 += str
                                }
                                if (item.startTime === '' || item.startTime === null) {
                                    let str = '开工时间,'
                                    isStr = true
                                    str1 += str
                                }
                                if (item.endTime === '' || item.endTime === null) {
                                    let str = '竣工时间,'
                                    isStr = true
                                    str1 += str
                                }
                                if (
                                    item.workContent === '' ||
                                    item.workContent === null
                                ) {
                                    let str = '工作内容,'
                                    isStr = true
                                    str1 += str
                                }
                                if (
                                    item.personInChar === '' ||
                                item.personInChar === null
                                ) {
                                    let str = '项目负责人,'
                                    isStr = true
                                    str1 += str
                                }
                                if (item.witness === '' || item.witness === null) {
                                    let str = '证明人,'
                                    isStr = true
                                    str1 += str
                                }
                                if (item.fileName === '' || item.fileName === null) {
                                    let str = '业绩附件,'
                                    isStr = true
                                    str1 += str
                                }
                                if (
                                    item.witnessPhone === '' ||
                                item.witnessPhone === null
                                ) {
                                    let str = '证明人联系电话,'
                                    isStr = true
                                    str1 += str
                                } else {
                                    if (!/^1[3-9]\d{9}$/.test(item.witnessPhone)) {
                                        let str = '委托代理联系电话格式不正确！'
                                        isStr = true
                                        str1 += str
                                    }
                                }
                                if (
                                    Date.parse(item.startDate) >=
                            Date.parse(item.endDate)
                                ) {
                                    let str = '结束时间必须大于开始时间,'
                                    isStr = true
                                    str1 += str
                                }
                                if (isStr) {
                                    this.errorMsg1.push(str1)
                                }
                            })
                            if (this.errorMsg1.length > 0) {
                                this.$emit('setError', 'firmPerformance')
                                adopt3 = false
                                return
                            } else {
                            // 企业主要业绩验证通过------------
                                adopt3 = true

                            }
                        } else {
                            this.errorMsg.push('必须包含至少一条有效数据')
                            adopt3 = false
                            this.$emit('setError', 'firmPerformance')
                        }
                    } else {
                    // 验证通过
                        adopt3 = true
                    }
                })
                // 所有必填验证通过了，才能进行提交，
                if (adopt && adopt2 && adopt3 ) {
                    if(Array.isArray(this.formData.outsourceTypeKey) ) {
                        this.formData.outsourceTypeKey =  this.formData.outsourceTypeKey.join(',')
                    }
                    if(Array.isArray(this.formData.outsourceType) ) {
                        this.formData.outsourceType =  this.formData.outsourceType.join(',')
                    }
                    await tenderRequest
                        .weeklyMaterialLeasingCreate(this.formData)
                        .then(() => {
                            this.clientPop('suc', '提交成功')
                        })
                        .catch(() => {
                            this.clientPop('err', '提交失败')
                        })
                }

            }
        },
        bytesToSize (byte) {
            return bytesToSize(byte)
        },
        async delFile (row) {
            await ossRequest
                .deleterByRelationId({ relationId: row.recordId })
                .then(() => {
                    row.fileName = ''
                    row.filePath = ''
                    row.fileSize = ''
                })
        },
        // 上传成功后
        handleAvatarSuccess (response, file, fileList, row) {
            const res = response.data[0]
            row.fileName = res.originalObjectName
            row.filePath = res.objectPath
            row.fileSize = res.objectSize
            row.upTime = res.gmtCreate
            this.$refs.enterpriseUpload.clearFiles() //上传成功之后清除历史记录
        },
        async uidBuilder (params, type = 'str') {
            let temp = []
            await uidBuilder(params).then(res => {
                temp = type === 'str' ? res[0] : res
            })
            return temp
        },
        // 上传前
        async beforeAvatarUpload (file) {
            const isLt2M = file.size / 1024 / 1024 < 20
            if (!isLt2M) {
                this.clientPop('err', '上传文件大小不能超过 20MB！')
            }
            return isLt2M
        },
        onblur (val) {
            console.log(val)
        },
        unitCodeBlur (creditCode) {
            if (creditCode === '') return
            openBiddingRequest.supplierQuery(creditCode).then(res => {
                if (res.data === null) {
                    this.clientPop(
                        'info',
                        '系统外包方库中的供应商库不存在，是否新增',
                        () => {
                            let data = this.formData.enrollPackage
                            // 重置当前页面数据
                            Object.assign(this.$data.formData, this.$options.data().formData)
                            // 将一些基础数据保存赋值
                            this.formData.unitCode = creditCode //将输入的信用代码保存
                            this.unitCodeState = false
                            this.formData.enrollPackage = data
                            this.formData.orgId =  this.userInfoData.userInfo.orgInfo.orgId //初始化机构id
                            this.formData.orgName =  this.userInfoData.userInfo.orgInfo.orgName //初始化机构名字
                            this.formData.founderName = localStorage.getItem('userName')
                            this.formData.tenderApplyId = this.$route.query.tenderId //招标id
                        }
                    )
                } else {
                    this.unitCodeState = true
                    this.formData.enterpriseAchievement = [] //企业主要业绩
                    this.formData.enrollCertificates = [] //资质信息
                    // 基本信息
                    this.formData.email = res.supplier.email //邮件
                    this.formData.fax = res.supplier.fax //传真
                    this.formData.isAbroad = res.supplier.isAbroadUnit //是否境外单位
                    this.formData.isOutsideSubcontractors = '2' //是否是库外分包商 1是，2不是
                    this.formData.legalRepresentative = res.supplier.deputy //法人代表
                    this.formData.orgId = res.supplier.orgId //	机构ID
                    this.formData.orgName = res.supplier.orgName //机构名称
                    this.formData.outsourceType =
                        res.supplier.supplierTypeValue.split(',') //外包方类型[id]
                    this.formData['outsourceTypeKey'] =
                        res.supplier.supplierTypeKey.split(',') //外包方类型[名字]
                    this.formData.registerAddress =
                        res.supplier.registerAddInfo //注册地址
                    this.formData.registerCaptial =
                        res.supplier.registerCapital //注册资本
                    this.formData.taxpayerType = res.supplier.taxTypeName //纳税人类别名字
                    this.formData.taxpayerValue = res.supplier.taxTypeValue //纳税人类别id
                    this.formData.telephone = res.supplier.contactTel //联系电话
                    this.formData.unitCode = res.supplier.creditCode //统一社会信用代码
                    this.formData.zipCode = res.supplier.postCode //	邮编
                    this.formData.creditLevel = res.supplier.creditLevel //信用等级
                    this.formData.unitName = res.supplier.supplierName //单位名称
                    this.formData.unitId = res.supplier.supplierId //	单位id
                    //企业主要业绩
                    for (
                        let index = 0;
                        index < res.performances.length;
                        index++
                    ) {
                        const obj = {
                            contractAmount:
                                res.performances[index].contractAmount, //合同金额
                            contractName: res.performances[index].contractName, //合同名称
                            endTime: res.performances[index].endDate, //竣工时间
                            fileName: res.performances[index].fileName, //证明附件名称
                            filePath: res.performances[index].dialogImage, //证明附件
                            personInChar: res.performances[index].projectLeader, //负责人
                            projectName: res.performances[index].projectName, //项目名称
                            recordId: res.performances[index].relationId, //记录ID
                            startTime: res.performances[index].startDate, //开工时间
                            witness: res.performances[index].witnessName, //证明人
                            witnessPhone: res.performances[index].witnessTel, //证明人电话
                            workContent: res.performances[index].workContect //工作内容
                        }
                        this.formData.enterpriseAchievement.push(obj)
                    }
                    //资质信息
                    for (
                        let index = 0;
                        index < res.qualificationinfos.length;
                        index++
                    ) {
                        const obj = {
                            certificateGrade:
                                res.qualificationinfos[index]
                                    .qualificationLevelName, //主营范围/资质等级
                            certificateGradeId:
                                res.qualificationinfos[index]
                                    .qualificationLevelId, //主营范围/资质等级
                            certificateNo: res.qualificationinfos[index].certNo, //证书编号
                            certificateType:
                                res.qualificationinfos[index].certTypeValue, //	证书类型
                            endTime: res.qualificationinfos[index].endDate, //有效结束日期
                            fileName: res.qualificationinfos[index].fileName, //文件名称
                            filePath: res.qualificationinfos[index].dialogImage, //文件路径
                            fileSize: res.qualificationinfos[index].size, //文件大小
                            recordId: res.qualificationinfos[index].relationId, //记录ID
                            startTime: res.qualificationinfos[index].startDate, //有效开始日期
                            upUser: res.qualificationinfos[index].founderName, //上传人
                            upUserId: res.qualificationinfos[index].founderId //上传人ID
                        }
                        this.formData.enrollCertificates.push(obj)
                    }
                    // this.formData.enrollTime = res.supplier.//报名日期
                    // this.formData.fixedTelephone = res.supplier.//	固定电话
                    // this.formData.packageIds = res.supplier. //包件IDS
                    // this.formData.packageName = res.supplier. //包件名称
                    // this.formData.projectName = res.supplier. //拟采购项目名称
                    // this.formData.tenderApplyId = res.supplier. //招标申请id
                    // this.formData.tenderApplyNo = res.supplier. //招标申请编号
                    // this.formData.tenderType = res.supplier. //招标类型
                    // this.unitCodeState2 = false
                }
            })
        },
        async random19Num () {
            let temp = ''
            await uidBuilder({ num: 1 }).then(res => {
                temp = res[0]
            })
            return temp
        },
        findById () {},
        onSuccess1 (response, file, fileList, recordId) {
            const index = this.enterpriseTableData.findIndex(value => {
                return value.recordId === recordId
            })
            // console.log('index', index)
            this.$set(this.enterpriseTableData[index], 'ifUpload', true)
            ossRequest
                .getObjectByRelationId({ relationId: recordId })
                .then(res => {
                    this.$set(
                        this.enterpriseTableData[index],
                        'filePath',
                        res[0].objectPath
                    )
                })
            this.$message({
                showClose: true,
                type: 'success',
                message: '上传成功'
            })
        },
        onSuccess2 (response, file, fileList, recordId) {
            const index = this.quaInfoTableData.findIndex(value => {
                return value.recordId === recordId
            })
            ossRequest
                .getObjectByRelationId({ relationId: recordId })
                .then(res => {
                    this.$set(
                        this.quaInfoTableData[index],
                        'fileName',
                        res[0].objectName
                    )
                    this.$set(
                        this.quaInfoTableData[index],
                        'fileSize',
                        res[0].objectSize
                    )
                    this.$set(
                        this.quaInfoTableData[index],
                        'upTime',
                        res[0].gmtCreate.slice(0, res[0].gmtCreate.indexOf(' '))
                    )
                    this.$set(
                        this.quaInfoTableData[index],
                        'filePath',
                        res[0].objectPath
                    )
                })
            this.$message({
                showClose: true,
                type: 'success',
                message: '上传成功'
            })
        },
        onSuccess3 (response, file, fileList, recordId) {
            const index = this.managerTableData.findIndex(value => {
                return value.recordId === recordId
            })
            // console.log('index', index)
            this.$set(this.managerTableData[index], 'ifUpload', true)
            ossRequest
                .getObjectByRelationId({ relationId: recordId })
                .then(res => {
                    this.$set(
                        this.managerTableData[index],
                        'filePath',
                        res[0].objectPath
                    )
                })
            this.$message({
                showClose: true,
                type: 'success',
                message: '上传成功'
            })
        },
        onSuccess4 (response, file, fileList, id) {
            const index = this.attachTableData.findIndex(value => {
                return value.id === id
            })
            ossRequest
                .getObjectByRelationId({ relationId: this.formData.billId })
                .then(res => {
                    const mapRes = {}
                    mapRes.fileName = res[0].objectName
                    mapRes.filePath = res[0].objectPath
                    mapRes.size = res[0].objectSize
                    mapRes.type = this.attachTableData[index].type
                    mapRes.upLoadTime = res[0].gmtCreate.slice(
                        0,
                        res[0].gmtCreate.indexOf(' ')
                    )
                    mapRes.recordId = res[0].recordId
                    // 用于删除
                    this.$set(this.attachTableData, index, mapRes)
                })
            this.$message({
                showClose: true,
                type: 'success',
                message: '上传成功'
            })
            console.log('fileList', fileList)
        },
        onError () {
            this.$message({
                showClose: true,
                type: 'error',
                message: '上传失败'
            })
        },
        async tableDel (key) {
            for (let i = 0; i < this.selection[key].length; i++) {
                const tableData = key + 'TableData'
                const index = this[tableData].findIndex(value2 => {
                    return value2.recordId === value2.recordId
                })
                //后端删除
                if (key === 'enterprise' || key === 'manager') {
                    // 企业主要业绩、企业主要管理人（没有fileName,是我自己加的ifUpload）
                    if (!this[tableData][index].ifUpload) {
                        //前端删除
                        this[tableData].splice(index, 1)
                        return
                    }
                    await ossRequest
                        .deleterRecordId({
                            recordId: this[tableData][index].recordId
                        })
                        .then(() => {
                            //前端删除
                            this[tableData].splice(index, 1)
                            this.$message({
                                showClose: true,
                                type: 'success',
                                message: '删除成功'
                            })
                        })
                        .catch(() => {
                            return
                        })
                    // 资质信息、附件信息
                } else {
                    if (!this[tableData][index].fileName) {
                        //前端删除
                        this[tableData].splice(index, 1)
                        return
                    }
                    await ossRequest
                        .deleterRecordId({
                            recordId: this[tableData][index].recordId
                        })
                        .then(() => {
                            //前端删除
                            this[tableData].splice(index, 1)
                            this.$message({
                                showClose: true,
                                type: 'success',
                                message: '删除成功'
                            })
                        })
                }
            }
        },
        // selectionChange (key, e) {
        //     this.selection[key] = e
        // },
        // eslint-disable-next-line no-unused-vars
        cellClick (row, column, cell, event) {
            if (column.label === '招标编号') {
                this.$router.push({
                    path: './biddingApplicationShow',
                    query: { tenderId: row.billId }
                })
            }
            //是第几行
            this.rowIndex = this.formData.enrollCertificates.findIndex(x => x === row) //资质信息
            this.rowIndex1 = this.formData.enterpriseAchievement.findIndex(x => x === row) //企业业绩
        },
        handleSelectionChange (e, event) {
            console.log(e)
            console.log('$event', event)
        },
        enterpriseAddInputBlur () {
            if (this.formData.contractName) {
                enrollRequest.achievementCreate(this.formData).then(res => {
                    console.log(res)
                })
            }
        },
        async managerAdd () {
            const random19Num = await this.random19Num()
            this.managerTableData.unshift({
                type: '',
                name: '',
                idCardNo: '',
                certNo: '',
                phone: '',
                endTime: '',
                addData: 1, //前端自定义判断是否是新增数据
                recordId: random19Num
            })
        },
        attachAdd () {
            this.attachTableData.unshift({
                fileName: '',
                filePath: '',
                size: '',
                type: '',
                upLoadTime: '',
                addData: 1
                // recordId: this.formData.billId
            })
            // this.$refs.upload4?.clearFiles()
        },
        async getTenderData () {
            await materialZhouCaiLeasingRequest
                .applyGetById({ id: this.tenderId })
                .then(res => {
                    this.formData.projectName = res.tenderName
                    this.formData.tenderApplyId = res.billId
                    this.formData.tenderApplyNo = res.billNo
                    this.formData.applyUnit = res.tenderUser
                    this.formData.tenderType = res.tenderClass
                    this.formData.enrollTime = this.getNowDate()
                })
        },
        getPackage () {
            materialZhouCaiLeasingRequest
                .packageListByEntity({
                    limit: 20,
                    page: 1,
                    tenderApplyId: this.tenderId
                })
                .then(async res => {
                    if (res.length === 0) return
                    this.formData.enrollPackage = res
                    this.formData.enrollPackage.forEach(item => {
                        item.changeType = 1
                    })
                    res.forEach(item => {
                        this.formData.packageName += item.name + '，'
                    })
                    this.formData.packageName =
                        this.formData.packageName.substr(
                            0,
                            this.formData.packageName.length - 1
                        )
                    // 前端显示的分包商
                    // this.pagination.total = res.totalCount || res.length
                })
        },
        onChangeTab (e) {
            const height  = $('#' + e.name).offset().top
            $.scrollTo(height - this.topHeight, 500)
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight (arr) {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById(arr[length - 1] + 'Con')) {
                    const lastConHeight = document.getElementById(
                        arr[length - 1] + 'Con'
                    )?.offsetHeight
                    this.lastConHeight = lastConHeight
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },
        delData () {},
        showBidding () {
            if (!this.tenderId) return // 前期需求可切换，现在不需要
            this.$notify.closeAll()
            this.$notify({
                title: '查看招标详情',
                dangerouslyUseHTMLString: true,
                message: `正式环境：客户端打开新页面<br>
              测试环境：手动打开新页面<br>
              <el-input cols="35" rows="10">http://localhost:8080/biddingApplicationShow?tenderId=${this.tenderId}</el-input>
              `,
                duration: 0
            })
        },
        getNowDate () {
            // 个位数前补0
            const zeroFill = function (num) {
                if (parseInt(num) < 10) {
                    num = '0' + num
                }
                return num
            }
            let nowtime = new Date()
            nowtime =
                zeroFill(nowtime.getFullYear()) +
                '-' +
                zeroFill(nowtime.getMonth() + 1) +
                '-' +
                zeroFill(nowtime.getDate())
            return nowtime
            // this.$set(this.formData, 'applyTime', nowtime)
        },
        cellClsNm ({ column }) {
            if (column.label === '') {
                return 'fixed-left'
            }
        },
        cellMouseEnter (row) {
            this.MouseEnterId = row.id
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        },
        reset () {
            this.clientPop(
                'info',
                '确认重置？重置后会将数据全部清空，请谨慎操作！',
                () => {
                    Object.assign(this.$data.formData, this.$options.data().formData)
                    this.getTenderData()
                    this.getPackage()
                }
            )
        },
        // 全选
        handleCheckAllChange (val) {
            this.formData.supplierTypeKey = val
                ? this.typeList.map(item => {
                    return item.kvKey
                })
                : []
            this.isIndeterminate = false
            // 循环拿到id
            this.typeList.map(item => {
                this.formData.supplierTypeValue.push(item.kvValue)
            })
            // 小规模纳税人禁用并自动切换成一般纳税人
            this.payTaxesTypeList.map(item => {
                if (item.kvValue == '1') {
                    this.$set(item, 'disabled', true)
                }
            })
            this.formData.taxTypeValue = '0'
            this.payTaxesTypeList.map(item => {
                if (this.formData.taxTypeValue == item.kvValue) {
                    this.formData.taxTypeName = item.kvKey
                }
            })
        },
        //外包方类型选择
        handleCheckedCitiesChange (value) {
            this.formData.supplierTypeValue = []
            let checkedCount = value.length
            this.checkAll = checkedCount === this.typeList.length
            this.isIndeterminate =
                checkedCount > 0 && checkedCount < this.typeList.length
            // 通过类型判断是否是小规模纳税人
            if (value.includes('其它') && checkedCount == 1) {
                this.payTaxesTypeList.map(item => {
                    if (item.kvValue == '1') {
                        this.$set(item, 'disabled', false)
                    }
                })
            } else {
                if (this.formData.taxTypeValue == '1') {
                    this.formData.taxTypeValue = '0'
                    this.payTaxesTypeList.map(item => {
                        if (this.formData.taxTypeValue == item.kvValue) {
                            this.formData.taxTypeName = item.kvKey
                        }
                    })
                }
                // 小规模纳税人禁用
                this.payTaxesTypeList.map(item => {
                    if (item.kvValue == '1') {
                        this.$set(item, 'disabled', true)
                    }
                })
            }
            // 循环拿到id
            this.typeList.map(item => {
                value.map(Valitem => {
                    if (item.kvKey == Valitem) {
                        this.formData.supplierTypeValue.push(item.kvValue)
                    }
                })
            })
        },
        // 一般纳税人选择
        radioChange (row) {
            this.payTaxesTypeList.map(item => {
                if (row == item.kvKey) {
                    this.formData.taxTypeValue = item.kvValue
                }
            })
        },
        //资质上传成功
        attachOnSuccess () {
            this.getObjectByRelationId()
        },
        //企业业绩上传成功
        attachOnSuccess1 () {
            this.getObjectByRelationId1()
        },
        //获取资质信息上传成功的对象
        getObjectByRelationId () {
            if (!this.relationId) return
            return ossRequest
                .getObjectByRelationId({ relationId: this.relationId })
                .then(res => {
                    this.$set(
                        this.formData.enrollCertificates[this.rowIndex],
                        'fileName',
                        res[0].objectName
                    )
                    this.$set(
                        this.formData.enrollCertificates[this.rowIndex],
                        'filePath',
                        res[0].objectPath
                    )
                    this.$set(
                        this.formData.enrollCertificates[this.rowIndex],
                        'fileSize',
                        res[0].objectSize
                    )
                    this.$set(
                        this.formData.enrollCertificates[this.rowIndex],
                        'upUserId',
                        res[0].userId
                    )
                    this.$set(
                        this.formData.enrollCertificates[this.rowIndex],
                        'upUser',
                        res[0].userName
                    )
                    this.$set(
                        this.formData.enrollCertificates[this.rowIndex],
                        'relationId',
                        this.relationId
                    )
                    this.$set(
                        this.formData.enrollCertificates[this.rowIndex],
                        'upTime',
                        res[0].gmtCreate.slice(0, res[0].gmtCreate.indexOf(' '))
                    )
                })
        },
        //获取企业主要业绩上传成功的对象
        getObjectByRelationId1 () {
            if (!this.relationId) return
            return ossRequest
                .getObjectByRelationId({ relationId: this.relationId })
                .then(res => {
                    this.$set(
                        this.formData.enterpriseAchievement[this.rowIndex1],
                        'fileName',
                        res[0].objectName
                    )
                    this.$set(
                        this.formData.enterpriseAchievement[this.rowIndex1],
                        'filePath',
                        res[0].objectPath
                    )
                })
        },
        //资质覆盖默认的上传行为，可以自定义上传的实现
        uploadBefore (params) {
            this.$Ajax
                .httpGet({
                    url: '/uid/builder?num=1',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
                .then(res => {
                    params.data.relationId = res[0]
                    this.relationId = res[0]
                    let obj = {
                        ...params.data,
                        files: params.file
                    }
                    this.$Ajax
                        .httpPostForm({
                            url: this.uploadUrl,
                            params: obj
                        })
                        .then(() => {
                            this.attachOnSuccess()
                        })
                })
                .catch(error => {
                    this.clientPop('err', error, this.handleClose)
                })
        },
        //企业业绩覆盖默认的上传行为，可以自定义上传的实现
        uploadBefore1 (params) {
            this.$Ajax
                .httpGet({
                    url: '/uid/builder?num=1',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
                .then(res => {
                    params.data.relationId = res[0]
                    this.relationId = res[0]
                    let obj = {
                        ...params.data,
                        files: params.file
                    }
                    this.$Ajax
                        .httpPostForm({
                            url: this.uploadUrl,
                            params: obj
                        })
                        .then(() => {
                            this.attachOnSuccess1()
                        })
                })
                .catch(error => {
                    this.clientPop('err', error, this.handleClose)
                })
        },
        // 企业业绩选中的数据
        selectClick1 (selection) {
            this.deleteData1 = selection
        },
        // 资质信息选中的数据
        selectClick2 (selection) {
            this.deleteData2 = selection
        },
        // 企业业绩删除
        delete1 () {
            this.deleteData1.map(item => {
                this.formData.enterpriseAchievement.map((newitem, index) => {
                    if (item.uuid == newitem.uuid) {
                        this.formData.enterpriseAchievement.splice(index, 1)
                    }
                })
            })
        },
        // 资质信息删除
        delete2 () {
            this.deleteData2.map(item => {
                this.formData.enrollCertificates.map((newitem, index) => {
                    if (item.uuid == newitem.uuid) {
                        this.formData.enrollCertificates.splice(index, 1)
                    }
                })
            })
        },
    }
}
</script>

<style lang="scss" scoped>
.title {
    position: absolute;
    top: 10px;
    right: 30px;
}
::v-deep.require::first-letter {
    color: red !important;
}
.buttons {
    display: flex;
    justify-content: center;
    .el-button {
        padding: 15px 50px;
    }
}
.form {
    margin-top: 10px;
}

.e-table {
    background: #fff;

    /* .top {
  .left {
    padding: 20px;
    padding-top: 0px;
  }
} */
}

.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 滚动条 */
.e-form {
    ::-webkit-scrollbar {
        width: 12px;
        height: 15px;
    }

    ::-webkit-scrollbar-track {
        -webkit-border-radius: 10px;
        border-radius: 10px;
        background: #f6f7f9;
    }

    ::-webkit-scrollbar-thumb {
        -webkit-border-radius: 10px;
        border-radius: 10px;
        background: rgba(204, 204, 204, 0.8);
    }
    ::-webkit-scrollbar-thumb:window-inactive {
        background: rgba(204, 204, 204, 0.4);
    }
}

// 附件栏
.affix {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .right {
        display: flex;
        align-items: center;
        i {
            margin-left: 10px;
        }
    }
}
// 境外单位
::v-deep .clearPadding .vxe-cell {
    padding: 0;
}
::v-deep .clearPaddingLeft .vxe-cell {
    padding-left: 0px;
}
::v-deep {
    .main-el-switch {
        position: relative;
        .el-switch__core {
            height: 24px;
            border-radius: 12px;
            &:after {
                left: 4px;
                top: 3px;
            }
        }
        &.el-switch {
            &.is-checked {
                .el-switch__core {
                    &:after {
                        margin-left: -20px;
                        left: 100%;
                    }
                }
            }
        }
        &.is-checked {
            .el-switch__label--left {
                opacity: 0;
            }
            .el-switch__label--right {
                opacity: 1;
            }
        }
        .el-switch__label {
            position: absolute;
            top: 0;
        }
        .el-switch__label--left {
            right: 0;
            color: #999;
            z-index: 1;
            margin-right: 8px;
        }
        .el-switch__label--right {
            left: 0;
            color: #fff;
            opacity: 0;
            margin-left: 8px;
        }
    }
}
</style>
